package com.gameplatform.common.response;

import com.gameplatform.common.enums.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.domain.Page;

@Data
@EqualsAndHashCode(callSuper = true)
public class PageResponse<T> extends BaseResponse<Page<T>> {
    private PageInfo pageInfo;

    @Data
    public static class PageInfo {
        private int pageNum;
        private int pageSize;
        private long total;
        private int totalPages;

        public PageInfo(Page<?> page) {
            this.pageNum = page.getNumber() + 1;
            this.pageSize = page.getSize();
            this.total = page.getTotalElements();
            this.totalPages = page.getTotalPages();
        }
    }

    public PageResponse(ResultCodeEnum resultCode, Page<T> data) {
        super(resultCode, data);
        this.pageInfo = new PageInfo(data);
    }

    public PageResponse(ResultCodeEnum resultCode, String message, Page<T> data) {
        super(resultCode, message, data);
        this.pageInfo = new PageInfo(data);
    }

    public static <T> PageResponse<T> success(Page<T> page) {
        return new PageResponse<>(ResultCodeEnum.SUCCESS, page);
    }

    public static <T> PageResponse<T> success(Page<T> page, String message) {
        return new PageResponse<>(ResultCodeEnum.SUCCESS, message, page);
    }
} 